<template>
  <div>
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item>首页</el-breadcrumb-item>
      <el-breadcrumb-item>余额录入</el-breadcrumb-item>
    </el-breadcrumb>
    <el-card class="box-card">
      <!-- 头部搜索 -->
      <el-row :gutter="10">
        <el-col :span="5">
          <div class="grid-content bg-purple">
            <el-form label-width="80px">
              <el-form-item label="邮箱：">
                <el-input
                  v-model="queryinfo.userEmail"
                  clearable
                  placeholder="请输入邮箱"
                  @clear="getmsgList"
                ></el-input>
              </el-form-item>
            </el-form>
          </div>
        </el-col>
        <el-col :span="5">
          <div class="grid-content bg-purple">
            <el-form label-width="80px">
              <el-form-item label="手机号：">
                <el-input
                  v-model="queryinfo.userTel"
                  clearable
                  placeholder="请输入手机号"
                  @clear="getmsgList"
                ></el-input>
              </el-form-item>
            </el-form>
          </div>
        </el-col>
        <el-button type="primary" icon="el-icon-search" @click="getmsgList"
          >搜索</el-button
        >
      </el-row>
      <!-- 数据列表 -->
      <el-table :data="tableData" stripe border style="width: 100%">
        <el-table-column type="index" label="#"> </el-table-column>
        <el-table-column prop="id" label="ID" width="80"> </el-table-column>
        <el-table-column prop="userTel" label="手机号码"> </el-table-column>
        <el-table-column prop="userEmail" label="邮箱"> </el-table-column>
        <el-table-column prop="levelName" label="等级">
        </el-table-column>
        <!-- <el-table-column prop="gmTokenNow" label="可挂卖ACC余额">
        </el-table-column>
        <el-table-column prop="gmTokenSum" label="可挂卖总数量ACC">
        </el-table-column> -->
        <el-table-column prop="" label="余额录入">
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="primary"
              icon="el-icon-edit"
              @click="addYE(scope.row.id)"
              >添加</el-button
            >
          </template>
        </el-table-column>
        <el-table-column label="余额记录">
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="danger"
              icon="el-icon-view"
              @click="LookYe(scope.row.id)"
              >查看</el-button
            >
          </template>
        </el-table-column>
      </el-table>
      <!-- 分页 -->
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :page-sizes="[10, 20, 30]"
        :page-size="queryinfo.pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      >
      </el-pagination>
    </el-card>
    <!-- 余额记录 -->
    <el-dialog title="余额记录" :visible.sync="dialogTableVisible" width="60%">
      <template>
        <el-table :data="YetableData" stripe border style="width: 100%"> 
          <el-table-column prop="id" label="ID"> </el-table-column>
          <el-table-column prop="createTime" label="时间"> </el-table-column>
          <el-table-column prop="gxequity" label="数量"> </el-table-column>
          <el-table-column label="操作类型"> 
            <template slot-scope="scope">
              <span v-if="scope.row.isJj">减</span>
              <span v-else>加</span>
            </template>
          </el-table-column>
          <el-table-column prop="type" label="币种"> </el-table-column>
          <el-table-column prop="yy" label="原因"> </el-table-column>
        </el-table>
      </template>
    </el-dialog>
    <!-- 余额录入 -->
    <el-dialog
      title="余额录入"
      :visible.sync="LRdialogVisible"
      @close="colseDialog"
      width="50%"
    >
      <el-row>
        <template>
          <el-select
            v-model="YEqueryinfo.coinId"
            placeholder="请选择币种"
            size="medium"
          >
            <el-option
              v-for="item in options"
              :key="item.id"
              :label="item.tokenZh"
              :value="item.id"
            >
            </el-option>
          </el-select>
        </template>
      </el-row>
      <el-row>
        <template>
          <el-select
            v-model="YEqueryinfo.isWay"
            placeholder="请选择操作类型"
            size="medium"
          >
            <el-option
              v-for="item in isWays"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </template>
      </el-row>
      <el-row
        ><el-input
          v-model="YEqueryinfo.token"
          placeholder="请输入数量"
        ></el-input
      ></el-row>
      <el-row>
        <el-input
          v-model="YEqueryinfo.tokenyy"
          placeholder="请输入原因"
        ></el-input>
      </el-row>

      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="GetCode()">确 定</el-button>
      </div>
    </el-dialog>
    <!-- 输入验证框 -->
    <el-dialog
      title="输入验证码"
      :visible.sync="centerDialog"
      width="30%"
      @close="colseDialog"
    >
      <el-row>
        <el-col :span="5" style="line-height:40px;">输入验证码:</el-col>
        <el-col :span="12">
          <el-input
            v-model="YEqueryinfo.codes"
            placeholder="请输入内容"
          ></el-input
        ></el-col>
      </el-row>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submit()">确定</el-button>
      </span>
    </el-dialog>
  </div>
</template>
<script>
export default {
  data() {
    return {
      YEqueryinfo: {
        smsid: "",
        codes: "",
        coinId: "",
        token: "",
        tokenyy: "",
        isWay: null,
      },
      queryinfo: {
        userTel: "",
        userEmail: "",
        pageIndex: 1,
        pageSize: 10,
      },
      options: [],
      isWays: [
        { value: false, label: "加" },
        { value: true, label: "减" },
      ],
      total: 0,
      tableData: [],
      YetableData: [],
      dialogTableVisible: false,
      LRdialogVisible: false,
      centerDialog: false,
    };
  },
  created() {
    this.getmsgList();
  },
  methods: {
    // 关闭对话框清空重置
    colseDialog() {
      this.YEqueryinfo.smsid = "";
      this.YEqueryinfo.codes = "";
      this.YEqueryinfo.coinId = "";
      this.YEqueryinfo.token = "";
      this.YEqueryinfo.tokenyy = "";
      this.YEqueryinfo.isWay = "";
    },
    // 提交余额录入
    async submit() {
      const { data: res } = await this.$http.post(
        "currencyAudit/InsertBalance",
        this.httputil(this.YEqueryinfo)
      );
      if (res.code !== 200) return this.$message.error(res.msg);
      this.$message.success(res.msg);
      this.LRdialogVisible = false;
      this.centerDialog = false;
      this.getmsgList();
    },
    // 获取验证码
    async GetCode() {
      this.centerDialog = true;
      const type = { type: 10 };
      const { data: res } = await this.$http.post(
        "currencyAudit/getSmsCode",
        this.httputil(type)
      );
      if (res.code !== 200) return this.$message.error(res.msg);
      this.$message.success("验证码"+res.msg);
      this.YEqueryinfo.smsid = res.data.id;
    },
    // 点击添加按钮打开对话框
    async addYE(id) {
      this.YEqueryinfo.id = id;
      this.LRdialogVisible = true;
      const { data: res } = await this.$http.post("currencyAudit/getCoinList");
      if (res.code !== 200) return this.$message.error(res.msg);
      this.options = res.data;
    },
    // 余额记录
    async LookYe(ids) {
      const id = { id: ids };
      const { data: res } = await this.$http.post(
        "currencyAudit/getjlList",
        this.httputil(id)
      );
      if (res.code !== 200) return this.$message.error(res.msg);
      this.YetableData = res.data;
      this.dialogTableVisible = true;
    },
    // 获取收益记录列表
    async getmsgList() {
      const { data: res } = await this.$http.post(
        "currencyAudit/getGxEquity",
        this.httputil(this.queryinfo)
      );
      if (res.code !== 200) return this.$message.error(res.msg);
      this.tableData = res.data.UserInfos;
      this.total = res.data.count;
    },
    // 页面数量发生改变
    handleSizeChange(newSize) {
      this.queryinfo.pageSize = newSize;
      this.getmsgList();
    },
    // 页数发生改变
    handleCurrentChange(newCurrent) {
      this.queryinfo.pageIndex = newCurrent;
      this.getmsgList();
    },
  },
};
</script>
<style lang="less" scoped>
.span3 {
  text-align: center;
}
.marginBt {
  margin-bottom: 15px;
}
.el-row{
  margin: 25px 0;
}
</style>
